/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_SEEK_CONFIG_H
#define SLE_SEEK_CONFIG_H

#include <stdint.h>
#include <stdbool.h>
#include "sle_device_config.h"

#define SLE_SEEK_DATA_MAX_LENGTH 255
#define SLE_SEEK_PHY_MAX 3

typedef enum {
    SLE_SEEK_FILTER_ALL_ALLOW   = 0x00,
    SLE_SEEK_FILTER_WLST_ALLOW  = 0x01,     //仅允许白名单设备
} SleSeekFilterPolicy_t;
typedef uint8_t SleSeekFilterPolicy;

typedef enum {
    SLE_SEEK_1M_PHY = 0x01,
    SLE_SEEK_2M_PHY = 0x02,
    SLE_SEEK_4M_PHY = 0x04,
} SleSeekPhyType_t;
typedef uint8_t SleSeekPhyType;

typedef enum {
    SLE_PASSIVE_SEEK = 0x00,
    SLE_ACTIVE_SEEK  = 0x01,
} SleSeekType_t;
typedef uint8_t SleSeekType;

#ifndef DEFAULT_SLE_SEEK_PARAM
#define DEFAULT_SLE_SEEK_PARAM

#define DEFAULT_SLE_SEEK_REPATE_FILTER true
#define DEFAULT_SLE_SEEK_FILTER_POLICY SLE_SEEK_FILTER_ALL_ALLOW
#define DEFAULT_SLE_SEEK_PHYS SLE_SEEK_1M_PHY
#define DEFAULT_SLE_SEEK_TYPE SLE_ACTIVE_SEEK
#define DEFAULT_SLE_SEEK_INTERVAL 1000
#define DEFAULT_SLE_SEEK_WINDOW 100

#endif //DEFAULT_SLE_SEEK_PARAM

typedef struct {
    SleDevAddrType addrType;
    bool repateFilter;   //重复过滤开关
    SleSeekFilterPolicy filterPolicy;
    SleSeekPhyType phys;
    SleSeekType type[SLE_SEEK_PHY_MAX];
    uint16_t interval[SLE_SEEK_PHY_MAX];    //取值范围[0x0004, 0xFFFF]，time = N * 0.125ms
    uint16_t window[SLE_SEEK_PHY_MAX];      //取值范围[0x0004, 0xFFFF]，time = N * 0.125ms
} SleSeekParam;

typedef struct {
    uint8_t eventType;
    SleDeviceAddress addr;
    SleDeviceAddress dirAddr;
    uint8_t rssi;                           //取值范围[-127dBm, 20dBm]，0x7F表示不提供信号强度指示
    uint8_t dataStatus;
    uint8_t dataLength;
    uint8_t *data;
} SleSeekResult;

typedef enum {
    SLE_SEEK_ENABLED_STATE = 0,
    SLE_SEEK_ENABLING_STATE = 1,
    SLE_SEEK_DISABLING_STATE = 2,
    SLE_SEEK_DISABLED_STATE = 3,
    /** keep SLE_SEEK_ERROR_STATE at the end of SEEKStatus */
    SLE_SEEK_ERROR_STATE = 0xFF,
} SleSeekState_t;
typedef uint8_t SleSeekState;

#ifndef SleSeekStateStr
#define SleSeekStateStr(seekState)                              \
    (seekState == SLE_SEEK_ENABLED_STATE) ? "ENABLED" :         \
    (seekState == SLE_SEEK_ENABLING_STATE) ? "ENABLING" :       \
    (seekState == SLE_SEEK_DISABLING_STATE) ? "DISABLING" :     \
    (seekState == SLE_SEEK_DISABLED_STATE) ? "DISABLED" :       \
    (seekState == SLE_SEEK_ERROR_STATE) ? "ERROR" : "UNKNOWN"
#endif

#endif // SLE_SEEK_CONFIG_H